package Year22_Month06.day25;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

public class 电话号码的字母组合 {

    List<String> list = new LinkedList<>();//用来存储结果集
    public List<String> letterCombinations(String digits) {
        if(digits.length() == 0 || digits == null) return list;
        String[] numString = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        backstacking(digits,numString,0);
        return list;
    }

    StringBuilder str = new StringBuilder();//构建一个字符串构造器，用来做对应的删减工作

    public void backstacking(String digits,String[] numString,int num){
        if(num == digits.length()){
            list.add(str.toString());
            return;
        }

        String myStr = numString[digits.charAt(num) - '0'];
        for (int i = 0; i < myStr.length(); i++) {
            str.append(myStr.charAt(i));
            backstacking(digits,numString,num+1);
            str.deleteCharAt(str.length() - 1);
        }
    }
}
